﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace _121_将对象转产为字典集合_LINQ扩展
{
    class Program
    {
        static void Main(string[] args)
        {
            产品基础信息[] 产品数组 =
            {
                new 产品基础信息
                {
                    PID=4007,
                    Name="产品1",
                    Size=123.45f,
                    Quatigy=65
                },
                new 产品基础信息
                {
                    PID=4008,
                    Name="产品2",
                    Size=77.01f,
                    Quatigy=100
                },
                new 产品基础信息
                {
                    PID=4012,
                    Name="产品3",
                    Size=45.13f,
                    Quatigy=25
                }
            };

            IDictionary<int, string> 字典 = 产品数组.ToDictionary(p => p.PID, p => p.Name);

            Console.WriteLine("转换得到的字典数据:");
            foreach (var i in 字典)
            {
                Console.WriteLine("{0}-{1}", i.Key, i.Value);
            }

        }
    }

    public class 产品基础信息
    {
        public int PID { get; set; }
        public string Name { get; set; }
        public float Size { get; set; }
        public int Quatigy { get; set; }
    }
}
